
using System;
using AtDevice;
using System.Linq;
using System.Xml.Linq;

namespace Interoperability
{
    public class PhonebookXmlExport : IPhonebookExport
    {
        public void ExportPhonebook(IPhoneBook phonebook, string filename)
        {
            var contacts =  from entry in phonebook.GetEntries()
                            select new XElement("contact",
                                        new XAttribute("id", entry.Index),
                                        new XElement("name", entry.Name),
                                        new XElement("number", entry.MobileNumber));
            
            XElement xml = new XElement("contacts", contacts);
            xml.Save(filename);
        }

        public string GetDescription()
        {
            return "XML export";
        }

        public string GetFileSuffix()
        {
            return ".xml";
        }
    }
}
